package com.unitedats.HR.Servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.unitedats.HR.Entity.HrDepartment;
import com.unitedats.common.Servlet.BasicServlet;
import com.unitedats.common.util.Common;
import com.unitedats.common.util.Default;
import com.unitedats.common.util.HtmlUtil;
import com.unitedats.common.util.WebUtil;

public class DepartmentChartDisplayServlet extends BasicServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		String displayMode = WebUtil.getParamValue(request, "mode", "view");

		try {
			HrDepartment root = (HrDepartment) dbm.executeNamedQuery(HrDepartment.class, Default.NAMED_QUERY_FIND_ROOT)
					.get(0);
			/*
			 * String rootStr = root.getName(); if
			 * (displayMode.equals("update")) rootStr = "<label>" +
			 * root.getName() +
			 * "</label><input type='hidden' name='depId' value='" +
			 * root.getId() + "'/> <input type='text' name='depName' value='" +
			 * root.getName() + "'/> ";
			 * 
			 * String tree =
			 * "<ul class='orgChartList' style=\"display:none;\" ><li>  " +
			 * rootStr + DepartmentUtil.drawDepChart(new StringBuilder(""),
			 * root, displayMode, dbm) + "</li></ul>";
			 */
			request.setAttribute("depChart",
					HtmlUtil.drawDepartmentNodeTree(root, "update".equals(displayMode), true, dbm));
			basicForward(request, response, "HR/DepartmentChart.jsp");

		} catch (Exception e) {
			Common.log(e);
		}
	}
}
